package com.keta.foundation.controller;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletRequest;
import javax.validation.Valid;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.keta.foundation.dataFilter.DynamicSpecifications;
import com.keta.foundation.entity.Monitor;
import com.keta.foundation.log.Log;
import com.keta.foundation.log.LogUtil;
import com.keta.foundation.service.MonitorService;
import com.keta.foundation.util.dwz.AjaxObject;
import com.keta.foundation.util.dwz.Page;


@Controller
@RequestMapping("/monitor")
public class MonitorController {

	private static final Logger logger = LoggerFactory.getLogger(MonitorController.class);

	private static final String MONITOR_LIST = "monitor/list";
	private static final String MONITOR_INDEX = "monitor/index";
	private static final String MONITOR_REPORT = "monitor/report";
	

	@Autowired
	private MonitorService monitorService;
	
	@RequiresPermissions("Monitor:view")
	@RequestMapping("/index")
	@Log(message="log")
	public String index(ServletRequest request, Page page, Model model) {
		
		Specification<Monitor> specification = DynamicSpecifications.byDataFilter(request, Monitor.class);
		page.setOrderDirection(Direction.DESC.toString());
		page.setOrderField("createTime");
		List<Monitor> monitorList = monitorService.getAll(specification, page);
		model.addAttribute("monitorList", monitorList);
		model.addAttribute("page", page);
		

		return MONITOR_INDEX;
	}
	
	

	/**
	 * Monitor列表入口
	 */
	@RequiresPermissions("Monitor:list")
	@RequestMapping("/list")
	public String list(ServletRequest request, Page page, Model model) {
		Specification<Monitor> specification = DynamicSpecifications.byDataFilter(request, Monitor.class);
		List<Monitor> monitorList = monitorService.getAll(specification, page);
		model.addAttribute("monitorList", monitorList);
		model.addAttribute("page", page);
		
		return MONITOR_LIST;
	}
	
	
	/**
	 * Monitor列表入口
	 */
	@RequiresPermissions("Monitor:report")
	@RequestMapping("/report")
	public String report() {
		
		
		return MONITOR_REPORT;
	}
	
	
	
	
	
	

	


	

	

}
